home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------*/
- /* filename - toptview.cpp */
- /* */
- /* function(s) */
- /* TOptionViewer member functions */
- /*------------------------------------------------------------*/
-
- /*------------------------------------------------------------*/
- /* */
- /* Turbo Vision - Version 1.0 */
- /* */
- /* */
- /* Copyright (c) 1991 by Borland International */
- /* All Rights Reserved. */
- /* */
- /*------------------------------------------------------------*/
-
- #define Uses_TKeys
- #define Uses_TOptionViewer
- #define Uses_TListViewer
- #define Uses_TScrollBar
- #define Uses_TEvent
- #define Uses_TCollection
- #include <tv.h>
- #include "TOption.h"
-
- #if !defined( __CTYPE_H )
- #include <ctype.h>
- #endif // __CTYPE_H
-
- #if !defined( __STRING_H )
- #include <String.h>
- #endif // __STRING_H
-
- #if !defined( __DOS_H )
- #include <Dos.h>
- #endif // __DOS_H
-
- #define cpOptionViewer "\x06\x06\x07\x06\x06"
-
- TOptionViewer::TOptionViewer( const TRect& bounds,
- TScrollBar *aHScrollBar,
- TScrollBar *aVScrollBar,
- TCollection *aList ) :
- TListViewer(bounds, 1, aHScrollBar, aVScrollBar),
- items( aList )
- {
- setRange( (aList == 0) ? 0 : aList->getCount() );
- if( range > 0 )
- focusItem( 0 );
- if( hScrollBar )
- hScrollBar->setRange( 0, optionWidth() - size.x + 3 );
- }
-
- TPalette& TOptionViewer::getPalette() const
- {
- static TPalette palette( cpOptionViewer, sizeof( cpOptionViewer )-1 );
- return palette;
- }
-
- void TOptionViewer::getText( char *dest, short item, short )
- {
- if (items != 0 )
- strcpy( dest, (const char *)(items->at(item)) );
- else
- *dest = EOS;
- }
-
- void TOptionViewer::handleEvent( TEvent& event )
- {
- if( (event.what == evMouseDown && event.mouse.doubleClick) ||
- (event.what == evKeyDown && event.keyDown.keyCode == kbEnter)
- )
- {
- endModal( cmOK );
- clearEvent( event );
- }
- else
- if( (event.what == evKeyDown && event.keyDown.keyCode == kbEsc) ||
- (event.what == evCommand && event.message.command == cmCancel)
- )
- {
- endModal( cmCancel );
- clearEvent( event );
- }
- else
- TListViewer::handleEvent( event );
- }
-
- int TOptionViewer::optionWidth()
- {
- int width = 0;
- if( items )
- {
- int count = items->getCount();
- for( int i = 0; i < count; i++ )
- {
- int T = strlen( (char *)(items->at(i)) );
- width = max( width, T );
- }
- }
- return width;
- }
-
- TCollection *TOptionViewer::list()
- {
- return items;
- }
-
- void TOptionViewer::newList( TCollection *aList )
- {
- destroy( items );
- items = aList;
- if( aList != 0 )
- setRange( aList->getCount() );
- else
- setRange(0);
- if( range > 0 )
- focusItem(0);
- drawView();
- }
-